#!/usr/bin/env bash

confirm() {
    # call with a prompt string or use a default
    read -r -p "${1:-Are you sure? [y/N]} " response
    case "$response" in
        [yY][eE][sS]|[yY]) 
            true
            ;;
        *)
            false
            ;;
    esac
}

symlink() {
    src=`pwd`/$1
    tgt=~/$1

    if [ -f $tgt ]; then
	if !(confirm "$tgt already exists, do you want to replace it, ? [y/N]"); then
	    return
	else
	    rm $tgt
	fi
    fi

    cmd="ln -s $src $tgt"
    echo $cmd
    eval $cmd
}

symlink .bashrc
symlink .zshrc
symlink .vimrc
